package com.marvels.approve.loan.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.marvels.approve.loan.dto.LoanCheckingDTO;
import com.marvels.approve.loan.service.ILoanCheckingService;
import com.marvels.approve.process.dto.LoanApplyCaseDTO;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;

/**征信复核
 * @author hejie
 *
 */
@RestController
@RequestMapping("approve/checking/service")
public class LoanCheckingController {
	@Autowired
	private ILoanCheckingService loanCheckingService;
	/**查询相关内容
	 * @param loanChecking
	 * @return
	 */
	@RequestMapping("qchecking")
	public MarvelsResultDTO queryChecking(@RequestBody LoanCheckingDTO loanChecking) {
		try {
			LoanCheckingDTO resultLoanChecking = loanCheckingService.findChecking(loanChecking);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),resultLoanChecking);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>征信复核FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>征信复核异常:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),
					"征信复核异常");
		}
	}
	
	/**保存征信复核信息
	 * @param loanChecking
	 * @return
	 */
	@RequestMapping("addchecking")
	public MarvelsResultDTO addChecking(@RequestBody LoanCheckingDTO loanChecking) {
		try {
			LoanCheckingDTO resultLoanChecking = loanCheckingService.saveChecking(loanChecking);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),resultLoanChecking);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>征信复核保存FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>征信复核保存:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),
					"征信复核保存");
		}
	}
	/**复核征信复核信息
	 * @param loanChecking
	 * @return
	 */
	@RequestMapping("complateChecking")
	public MarvelsResultDTO complateChecking(@RequestBody LoanCheckingDTO loanChecking) {
		try {
			LoanCheckingDTO resultLoanChecking = loanCheckingService.complateChecking(loanChecking);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),resultLoanChecking);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>征信复核完成任务FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>征信复核完成任务:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),
					"征信复核完成任务");
		}
	}
}
